package com.itheima.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.util.BaseContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
/*
登录功能设计完成后可以启用
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        Employee employee = (Employee) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        metaObject.setValue("createUser", employee.getId());
        metaObject.setValue("createTime", LocalDateTime.now());

        //metaObject.setValue("createUser", BaseContext.getCurrentId());
        metaObject.setValue("createUser" , 2L);

        metaObject.setValue("updateTime", LocalDateTime.now());

        //metaObject.setValue("updateUser",BaseContext.getCurrentId());
        metaObject.setValue("updateUser" , 2L);

//        metaObject.setValue("updateUser", employee.getId());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        Employee employee = (Employee) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        metaObject.setValue("updateTime",LocalDateTime.now());

        //metaObject.setValue("updateUser",BaseContext.getCurrentId());
        metaObject.setValue("updateUser" , 2L);

//        metaObject.setValue("updateUser", employee.getId());
    }
}
